Thank you for your clear and thorough summary. It's very helpful.
One suggestion about the Prototype Chain example. It would be more clear if use a different object to assign the prototype to the empty constructor other than "Guy". For me I was confused at the first time that why we need to assign the "Guy.prototype" if we have "Guy.apply" since "Guy" already have the aboutMe(). I commented out the 3 lines for Guy.prototype assignment, and it is still working.
Here is the testing code I use to understand the concept (I am using NGuy for the prototype assignment and Guy for constructor):
function Guy(name, awesome) {
this.name = name;
this.awesome = awesome;
}
function NGuy(name, awesome) {
this.name = name;
this.awesome = awesome;
//this.aboutMe = function() {
//return this.awesome ? "I'm awesome!" : "I'm lame :(";
//};
}
NGuy.prototype.aboutMe = function() {
return this.awesome ? "I'm awesome!" : "I'm lame :(";
};
//var guy1= new NGuy("Max",true);
//console.log(guy1.aboutMe());
function NewGuy() {
Guy.apply(this, arguments);
}
var ctor = function() {}; // empty constructor
ctor.prototype = NGuy.prototype;
NewGuy.prototype = new ctor();
NewGuy.prototype.shout = function() {
return "Aaaaaaahhhh";
}
var john = new NewGuy("New John", true);
console.log(john.aboutMe());
console.log(john.shout());